//------------------------------------------------------------------------------
//!	@file	DumpArray.c
//!	@brief
//!		Dump Array
//!
//!	@Description
//!		Dump various types of arrays.
//!
//!
//!	Originally Developed: July, 1997 to October, 1999
//!
//!	$Id: DumpArray.c 125 2013-01-30 23:59:23Z ac.verbeck@gmail.com $
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
//	Copyright and Disclaimer Notice
//
//	Copyright (c) 2013 A.C. Verbeck
//
//	This file is part of CreateLUT: A LUT creation library.
//
//	CreateLUT is free software: you can redistribute it and/or modify
//	it under the terms of the GNU General Public License as published by
//	the Free Software Foundation, either version 3 of the License, or
//	(at your option) any later version.
//
//	CreateLUT is distributed in the hope that it will be useful,
//	but WITHOUT ANY WARRANTY; without even the implied warranty of
//	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//	GNU General Public License for more details.
//
//	You should have received a copy of the GNU General Public License
//	along with CreateLUT.  If not, see <http://www.gnu.org/licenses/>.
//
//------------------------------------------------------------------------------

#include <stdio.h>
#include <stdlib.h>
#include <memory.h>

#include <stdint.h>
#include <stdbool.h>

#include "DumpArray.h"


//
//	Name:
//		DumpArray_UInt8
//
//	Description:
//		Dump an array (tab) of length (len) to file name (fn).
//		Used for debugging.
//
//	Parameters:
//		char*		fn:		Input file
//		uint8_t*	tab:	Table of values to save
//		uint16_t	len:	Length of table
//
//	Returns:
//		(No direct return)
//		Indirect: The array is saved
//
void DumpArray_UInt8(char* fn, uint8_t* tab, uint16_t len)
{
	FILE*	OutFile;
	uint16_t	i;

	OutFile = fopen(fn,"wt");
	if (OutFile == NULL) {
		printf("File open error: %s\n",fn);
		exit(1);
	}

	for (i=0; i<len; i++) fprintf(OutFile, "%d\n",tab[i]);

	fclose(OutFile);
}


//
//	Name:
//		DumpArray_uint16_t
//
//	Description:
//		Dump an array (tab) of length (len) to file name (fn).
//		Used for debugging.
//
//	Parameters:
//		char*		fn:		Input file
//		uint8_t*	tab:	Table of values to save
//		uint16_t	len:	Length of table
//
//	Returns:
//		(No direct return)
//		Indirect: The array is saved
//
void DumpArray_uint16_t(char* fn, uint8_t* tab, uint16_t len)
{
	FILE*	OutFile;
	uint16_t	i;

	OutFile = fopen(fn,"wt");
	if (OutFile == NULL) {
		printf("File open error: %s\n",fn);
		exit(1);
	}

	for (i=0; i<len; i++) fprintf(OutFile, "%d\n",tab[i]);

	fclose(OutFile);
}


//
//	Name:
//		DumpArray_Double
//
//	Description:
//		Dump an array (tab) of length (len) to file name (fn).
//		Used for debugging.
//
//	Parameters:
//		char*		fn:		Input file
//		uint8_t*	tab:	Table of values to save
//		uint16_t	len:	Length of table
//
//	Returns:
//		(No direct return)
//		Indirect: The array is saved
//
void DumpArray_Double(char* fn, double* tab, uint16_t len)
{
	FILE*	OutFile;
	uint16_t	i;

	OutFile = fopen(fn,"wt");
	if (OutFile == NULL) {
		printf("File open error: %s\n",fn);
		exit(1);
	}

	for (i=0; i<len; i++) fprintf(OutFile, "%f\n",tab[i]);

	fclose(OutFile);
}

//
//	End of DumpArray.c
//
